# !/usr/bin python3
# encoding: utf-8 -*-
# @file     : order_actions.py
# @author   : 沙陌 Matongxue_2
# @Time     : 2023/9/5 22:04
# @Copyright: 北京码同学
from common.driver import DriverOperate
from pages.buyer.goods_page import GoodsDetailPage
from pages.buyer.home_page import HomePage


class BuyerOrderActions:

    def buy_now(self, text='沙陌', pay_type='货到付款', receive_time='任意时间'):
        HomePage().send_keys_search(text).click_shop_btn().click_first_goods()
        # 点完第一个商品之后页面会新窗口打开商品详情页，所以我们要先完成driver切换
        DriverOperate.globalDriverOperate.switch_to_window()
        checkout_page = GoodsDetailPage().click_buy_now().click_first_address()
        if pay_type == '货到付款':
            checkout_page.click_huodao_pay()
        elif pay_type == '在线支付':
            checkout_page.click_online_pay()

        if receive_time == '任意时间':
            checkout_page.click_any_time()
        elif receive_time == '仅工作日':
            checkout_page.click_only_work()
        elif receive_time == '仅休息日':
            checkout_page.click_only_not_work()
        return checkout_page.click_submit_order().get_order_sn()

    def order_accept_goods(self, order_sn):
        HomePage().click_enter_personcenter() \
            .click_my_order_menu() \
            .send_keys_search(order_sn) \
            .click_searchbtn() \
            .click_shouhuo_btn() \
            .click_confirm()

    def return_goods(self, order_sn, user='shamo', desc='这是问题描述随便写的'):
        HomePage().click_enter_personcenter() \
            .click_my_order_menu() \
            .send_keys_search(order_sn) \
            .click_searchbtn() \
            .click_after_sales() \
            .click_shenqing() \
            .click_returngoods() \
            .select_type() \
            .send_keys_user(user) \
            .select_reason() \
            .send_keys_content(desc) \
            .click_submit()

    def order_comment(self, order_sn, level_name='好评', content='这是评论内容，不要多想'):
        HomePage().click_enter_personcenter() \
            .click_my_order_menu() \
            .send_keys_search(order_sn) \
            .click_searchbtn() \
            .click_comment() \
            .click_level(level_name) \
            .send_keys_content(content) \
            .click_submit()
